﻿using System;

namespace ECommerce.Administration.Controls
{
	public partial class EditLanguage : AdminBaseUsercontrol
	{
		private Service.ILanguageService _LanguageService;

		protected void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
			{
				LabelEditLanguageTitle.Text = GetLocalResourceString("Admin.EditLanguage.Add.Title");
				ButtonSave.Text = GetLocalResourceString("Admin.SaveButtonText");
			}
		}

		protected void ButtonSave_Click(object sender, EventArgs e)
		{
			var theLanguage = new Data.Entity.Language();

			theLanguage.Name = TextLanguageName.Text;
			theLanguage.LanguageCulture = TextLanguageCulture.Text;
			theLanguage.Published = CheckBoxPublished.Checked;
			theLanguage.DisplayOrder = int.Parse(TextDisplayOrder.Text.Trim());

			if (_LanguageService == null)
			{
				_LanguageService = new Service.LanguageService();
			}

			_LanguageService.CreateNewLanguage(theLanguage);
		}
	}
}